from django.shortcuts import render
from django.http import JsonResponse
from demo.models import User
# Create your views here.
def login(request):

    if(request.method == 'GET'):
        user = User.objects.get(username='ysf')
        if(user.pwd == request.GET.get('pwd')):

            return JsonResponse({'code':200,'data': "登陆成功"})
        else:
            return JsonResponse({'code': 1, 'data': "账号密码错误"})
def add(request):
    user = User(username='ysf',pwd='123456')
    user.save()
    return JsonResponse({'code': 200, 'data': "添加用户成功"})
def updata(request):
    user = User.objects.get(username='ysf')
    user.pwd = "123456789"
    user.save()
    return JsonResponse({'code': 200, 'data': "修改密码成功"})
def  delete(request):
    user = User.objects.get(username='zhangsan')
    user.delete()
    return JsonResponse({'code': 200, 'data': "删除用户成功"})


